package com.lankystar.sos.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.lankystar.sos.service.IPharmacyInterface;
import com.lankystar.util.ResUtil;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("sos")
@Namespace("/")
@Component
@Scope("prototype")
@Results({
	@Result(name="success",type="json")
})
public class PharmacyAction extends ActionSupport{

	private static final long serialVersionUID = 1L;

	@Autowired
	private IPharmacyInterface pharmacyInterface;
	private Integer userId;
	private double longitude;
	private double latitude;
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public double getLongitude() {
		return longitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	public double getLatitude() {
		return latitude;
	}
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	
	@Action(value="queryPharmacylist")
	public String queryPharmacylistMethod(){
		Map<String, Object> map = new HashMap<>();
		try {
			map.put("datas", pharmacyInterface.queryPharmacylistMethod(longitude,latitude));
			map.put("code", 1);
			map.put("msg", "附近药店列表查询成功！！");
		} catch (Exception e) {
			map.put("code", 0);
			map.put("msg", "附近药店列表查询失败！！");
		}
		ResUtil.toJson(ServletActionContext.getResponse(), map);
		return SUCCESS;
	}
}
